const base_url = "https://nideshop.bluej.cn/api/";


//从缓存中获取 token
var token = wx.getStorageSync('token');

function ask(options) {
  wx.showLoading({
    title: '加载中',
    mask: true
  });
  let { 
    url,
    method = 'get',
    data = {}
  } = options;
  return new Promise((resolve, reject) => {
    wx.request({
      url: base_url + url,
      method: method,
      data: data,
      method: method,
      header: {
        'content-type': 'application/json', // 默认值
        'X-Nideshop-Token': token,
      },
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      },
      complete: () => {
        wx.hideLoading();
      }
    })
  })
}

module.exports = {
  ask
}